#include <yatak/yatak.h>
#include <yatak/port.h>
#include <timer.h>

static void play_sound(uint32 nFrequence);
static void nosound();

//Play sound using built in speaker
static void play_sound(uint32 nFrequence)
{
	uint32 Div;
	uint8 tmp;

	Div = 1193180 / nFrequence;
	outportb(0x43, 0xb6);
	outportb(0x42, (uint8)Div);
	outportb(0x42, (uint8)(Div >> 8));
	tmp = inportb(0x61);
	if (tmp != (tmp | 3))
	{
		outportb(0x61, tmp | 3);
	}
}

//make is shutup
static void nosound()
{
	uint8 tmp = (inportb(0x61) & 0xFC);
	outportb(0x61, tmp);
}

//Make a beep
void beep() 
{
	play_sound(1000);
	timer_wait(10);
	nosound();
}
